//
// Created by hay boy on 2022/6/27.
//

#ifndef ALGORITHMS_LINKEDSTACK_H
#define ALGORITHMS_LINKEDSTACK_H
#include "../Stack.h"
#include "../../chainNode/ChainNode.h"
template<class T>
class LinkedStack : public Stack<T> {
public:
    explicit LinkedStack(int initialCapacity=10){
        stackTop = nullptr;
        stackSize = 10;
    }
    ~LinkedStack();
    bool empty() const{
        return stackSize == 0;
    }
    int size()const{
        return stackSize;
    }
    T& top(){
        if(stackSize==0){
            throw StackEmpty();
        }
        return stackTop->element;
    }
    void pop();
    void push(const T& theElement){
        stackTop = new ChainNode<T>(theElement,stackTop);
        stackSize++;
    }
    void clear();
private:
    ChainNode<T>* stackTop;
    int stackSize;
};

template<class T>
LinkedStack<T>::~LinkedStack() {
    while(stackTop!=nullptr){
        ChainNode<T>* nextNode = stackTop->next;
        delete stackTop;
        stackTop = nextNode;
    }
}

template<class T>
void LinkedStack<T>::pop() {

}

template<class T>
void LinkedStack<T>::clear() {
    while(stackTop!=nullptr){
        ChainNode<T>* nextNode = stackTop->next;
        delete stackTop;
        stackTop = nextNode;
    }
    stackSize = 0;
}


#endif //ALGORITHMS_LINKEDSTACK_H
